package com.health.userbackstage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.health.userbackstage.pojo.CheckGroup;
import com.health.userbackstage.pojo.CheckItem;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface CheckItemMapper extends BaseMapper<CheckItem> {
    @Select("Select * from checkitem")//需要更改为单表查询，前段页面暂时不用多表联查
//    "SELECT cg.*,ci.`id`  ciid\n" +//多表联查此处不需要
//    "FROM checkgroup_checkitem cc,checkgroup cg,checkitem ci\n" +
//    "WHERE cg.`id`=cc.`checkgroup_id` AND ci.`id`=cc.`checkitem_id`"
    @ResultMap("checkitemMap")
    List<CheckItem> findAll();

    @Select("SELECT cg.`id`  cgid\n" +
            "FROM checkgroup_checkitem cc,checkgroup cg,checkitem ci\n" +
            "WHERE cg.`id`=cc.`checkgroup_id` AND ci.`id`=cc.`checkitem_id`")
    List<Integer> findCgid(Integer ciid);

    @Select("select * from checkitem")
    List<CheckItem> findCheckItems();

    @Update("update checkitem " +"\n"+
            "set code=#{code}," +"\n"+
            "name=#{name}," +"\n"+
            "sex=#{sex}," +"\n"+
            "age=#{age}," +"\n"+
            "type=#{type}," +"\n"+
            "price=#{price}," +"\n"+
            "remark=#{remark}," +"\n"+
            "attention=#{attention} " +"\n"+
            "where id=#{id}")
    int updateById(CheckItem checkItem);

    @Insert("insert into checkItem values (#{id},#{code},#{name},#{sex},#{age},#{price},#{type},#{attention},#{remark})")
    int insert(CheckItem checkItem);

    @Delete("delete from checkItem where id = #{id}")
    int deleteById(Integer id);

    @Select("select * from checkitem where code=#{checkItem.code}")
    CheckItem selectOneByCode(@Param("checkItem") CheckItem checkItem);

    @Select("select * from checkitem where name=#{checkGroup.name}")
    CheckItem selectOneByName(@Param("checkItem") CheckItem checkItem);

    @Select("select * from checkitem where helpcode=#{checkGroup.helpcode}")
    CheckItem selectOneByHelpCode(@Param("checkItem") CheckItem checkItem);
}
